/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * TrainingBook
 * Copyright (C) Arnaud Duval 2010 <arnaud.duval@gmail.com>
 * 
 * TrainingBook is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * TrainingBook is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "track-view-dialog.hpp"

//Include of iostream should be removed after debug
#include <iostream>


///@brief Constructor
TrackViewDialog::TrackViewDialog(Gtk::Window *parent, Track trace)
{
    //Set the border width of the window
    set_border_width(0);
    myArea.SetTilesRepository("http://tile.openstreetmap.org/");
    ///@bug Quality of the repository should be tested (all tiles present ?)
    //myArea.SetTilesRepository("http://arnoduval.free.fr/tiles/osm_original/");
	myArea.set_size_request(600,400);
	myArea.SetBoundingBox(trace.MinLat(), trace.MaxLat(), trace.MinLon(), trace.MaxLon());
	myArea.AddTrack(trace);

	//myArea.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON1_MOTION_MASK);
	//myArea.signal_button_press_event().connect(sigc::mem_fun(*this,
 //&TrackViewDialog::on_map_area_click), false);
	//myArea.signal_motion_notify_event().connect(sigc::mem_fun(*this,
 //&TrackViewDialog::on_map_area_move), false);

	//init = false;

	//Add the drawing area
	get_vbox()->pack_start(myArea, Gtk::PACK_EXPAND_WIDGET);
	
	//Ajout de boutons
	add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
	add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
	
	show_all();
}

///@brief Destructor
TrackViewDialog::~TrackViewDialog()
{

}
/*
///@brief Action when clicking on the MapArea
bool TrackViewDialog::on_map_area_click(GdkEventButton* event)
{
	if((event->type == GDK_2BUTTON_PRESS)&&(event->button == 1))
	{
		myArea.IncreaseZoomLevel();
		return true;
	}
	else if((event->type == GDK_2BUTTON_PRESS)&&(event->button == 3))
	{
		myArea.DecreaseZoomLevel();
		return true;
	}
	else
		return false;
}

///@brief Action when moving the mouse
bool TrackViewDialog::on_map_area_move(GdkEventMotion* event)
{
	std::cout << "Je bouge la souris\n" << (int)event->x << "\t" << (int)event->y << "\n";
	if(init)
		myArea.Move((int)event->x - lastx, (int)event->y - lasty);
	lastx = (int)event->x;
	lasty = (int)event->y;
	init = true;

	return false;
}*/